﻿public class Function
{
	//boolean陣列, 紀錄是否為質數
	public boolean[] prime = new boolean[ 1000010 ] ;
	public int gcd( int a , int b )
	{
		//求最大公因數
		if( b == 0 )
			return a ;
		else
			return gcd( b , a % b ) ;
	}
	public int sum( int a , int b )
	{
		return a + b ;
	}
	public int dif( int a , int b )
	{
		return a - b ;
	}
	public void Sieve( )
	{
		//篩法求質數
		//紀錄1000000以內的質數
		int i , j ;
		prime[ 0 ] = prime[ 1 ] = true ;
		for( i = 2 ; i < 1000010 ; i++ )
			if( prime[ i ] == false )
				for( j = i+i ; j < 1000010 ; j += i )
					prime[ j ] = true ;
	}
	public int isprime( int a )
	{
		//若  a在測試範圍內
		if( a <= 1000000 && a > 0 )
		{
			// 若 prime[ a ] == 0(false) 為質數 
			if( prime[ a ] == false  )
				return 1 ;
			else
				return 0 ;
		}
		else
			return 0 ;
	}
	public int GetBMI( int W , int H )		
	{		
		double w = (double) W ;		
		double h = (double) H ;		
		if( h > 0 )		
		{		
			h /= 100 ;		
			return (int)( w/(h*h) ) ;		
		}		
		else		
			return -1 ;		
	}		
	public int CheckNameOK( String name )		
	{		
		//Name is illigal or not		
		if( name.length( ) <= 0 || name.length( ) > 10 )		
			return 0 ;		
		for( int i = 0 ; i < name.length( ) ; i++ )		
		{		
			if( ( name.charAt( i ) <= '9' && name.charAt( i ) >= '0' )		
					|| ( name.charAt( i ) <= 'z' && name.charAt( i ) >= 'a' )		
					|| ( name.charAt( i ) <= 'Z' && name.charAt( i ) >= 'A' ) )	;		
			else		
				return 0 ;		
		}		
		//Is Login, check data		
		//Checking Name is OK in the file or not		
		//OK, Read User Infomation		
		return 1 ;		
	}
}
